using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace PlayTime
{
    public struct PlayerAndCardCombination
    {
        public Position pos;
        public Card card;
    }
    public class Trick        
    {
        private const int nCardPerTrick = 4;
        private CardSuit m_eLeadSuit;
        private Position m_eWinnerPosition;
        private Position m_eNextPositionToLead;
        private ArrayList m_cTrickCard;
        private Card m_cTopCard = null;
        public Trick()
        {
            m_cTrickCard = new ArrayList(nCardPerTrick);
        }
        public int CardPassed
        {
            get { return m_cTrickCard.Count; }
        }
        public CardSuit LeadSuit
        {
            get { return m_eLeadSuit; }
        }
        public Position NextPositionToLead
        {
            get { return m_eNextPositionToLead; }
            set { m_eNextPositionToLead = value; }
        }
        internal  void PassCard(Card card, Position position,Call contract)
        {
            PlayerAndCardCombination  aPlayerCard;
            aPlayerCard.card = card;
            aPlayerCard.pos = position;
            m_cTrickCard.Add(aPlayerCard);
            if (m_cTopCard == null)
            {
                m_cTopCard = card;
                Winner = position;
                m_eLeadSuit = card.CardSuit;
            }
            else
            {
                if (card.CardSuit == m_cTopCard.CardSuit )
                {
                    if (card.CardType > m_cTopCard.CardType)
                    {
                        m_cTopCard = card;
                        Winner = position;
                    }
                }
                else if ((int)card.CardSuit == (int)contract.BidDenomination)
                {
                    m_cTopCard = card;
                    Winner = position;
                }
            }
        }

        public TrickStatus TrickStatus
        {
            get
            {
                if (m_cTrickCard.Count == nCardPerTrick)
                {
                    return TrickStatus.CurrentTrickComplete;
                }
                return TrickStatus.CurrentTrickInComplete;
            }
        }
        public Position Winner
        {
            get {   return m_eWinnerPosition; }
            set { m_eWinnerPosition = value; }

        }

        //internal void SetVerdict(Call contract)
        //{
        //    Card cardType = GetHigestCardinTrick(m_eLeadSuit);
        //    {
        //    }
        //    if ( (int)contract.BidDenomination == (int)LeadSuit)
        //    {

        //    }
        //    else if (contract.BidDenomination == BidDenomination.NT)
        //    {

        //    }
        //    else
        //    {

        //    }
        //}

        //private Card GetHigestCardinTrick(CardSuit suit)
        //{
        //    PlayerAndCardCombination playerCard = (PlayerAndCardCombination)m_cTrickCard[0];
        //    Card curcard = (Card)playerCard.card;
        //    Card curHigh = null;
        //    if (curcard.CardSuit== suit)
        //    {
        //        curHigh = curcard;
        //    }

        //    for (int i =1;i<m_cTrickCard.Count;i++)
        //    {
        //        playerCard = (PlayerAndCardCombination)m_cTrickCard[i];
        //        curcard = (Card)playerCard.card;
        //        curcard = (Card)m_cTrickCard[i];
        //        if (curcard.CardSuit == suit)
        //        {
        //            if (curcard.CardType > curHigh.CardType)
        //            {
        //                curHigh = curcard;
        //            }
        //        }
        //    }
        //    return curHigh;
        //}
    }
}
